# -*- coding: utf-8 -*-
class DeliveryOrder < ActiveRecord::Base
  #attr_accessor :tax_amount,:cost_amount

  has_many :delivery_order_details ,:dependent => :destroy  #级联删除子表
  has_many :delivery_order_hxes    ,:dependent => :destroy  #级联删除子表
  #belongs_to :from_warehouse, :class_name => "Warehouse" , :foreign_key => :to_warehouse_id
  #belongs_to :to_warehouse, :class_name => "Warehouse" , :foreign_key => :to_warehouse_id
  belongs_to :sale_order
  belongs_to :warehouse
  belongs_to :employee
  belongs_to :order_type
  belongs_to :department
  belongs_to :company
  belongs_to :customer

  scope :findAllDelivery, ->(conditionsStr,conditionsHash,paramsHash) { includes( [:sale_order,:delivery_order_details]).where([conditionsStr,conditionsHash]).offset(paramsHash[:offset]).limit(paramsHash[:limit]).order('delivery_orders.updated_at DESC')}

  scope :countAllDelivery, ->(conditionsStr,conditionsHash) { includes( [:sale_order,:delivery_order_details]).where([conditionsStr,conditionsHash]).count()}

end
